Skip to content

Conversation

@bkietz
Copy link
Member

@bkietz bkietz commented Jul 26, 2024

Construct nanoarrow::UniqueSchemas with a tiny C++ DSL:

  schema{children{
      {"i", "i32",
       metadata{
           "some_key=some_value",
       }},
      {"i", "i32",
       dictionary{{"u"}},
       metadata{
           "some_key=some_value",
       },
       ARROW_FLAG_NULLABLE},
  }};

The python-equivalent signature is approximately:

def schema(format="+s", name="", metadata=[], flags=0, children=[], dictionary=None):

After the first two arguments, all the rest can be provided in any order.

@bkietz bkietz requested a review from paleolimbot July 26, 2024 21:48
Copy link
Member

@paleolimbot paleolimbot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some initial thoughts! If we're really headed for readable schema construction, Arrow C++-like constructors (e.g., int32("field name")) are more likely to be what we want (and might be substantially less complicated to implement). I probably would have gone towards templating on ArrowType and using our C library constructors instead of introducing another way to create schemas.

It's worth looking at how https://github.com/man-group/sparrow does this (I think they have something pretty similar to construct types/schemas).

I was hoping to merge #561 before adding anything to the testing library (it could use a review!).


/// @}

namespace dsl {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe factory?

/// \brief An alias to express a sequence of key value pairs.
///
/// Each pair is a string formatted like "key=value".
using metadata = std::vector<std::string>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would std::vector<std::pair<std::string, std::string>> work? I'm not sure the world is clamouring to create metadata keys that contain the = symbol but it seems like it would be nice to avoid string parsing if we can.

Comment on lines +1915 to +1925
schema{children{
{"i", "int32 field name",
metadata{
"some_key=some_value",
}},
{"i", dictionary{"u"}, "dictionary field name",
metadata{
"some_key=some_value",
},
ARROW_FLAG_NULLABLE},
}};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In tests I think I would still prefer to see the C calls (but perhaps this is not where you were headed with this)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants